<extend name="Public:base" />
<block name="content">
	<div class="page-header">
		<h1>
			{$breadcrumb2}
			<small>
				<i class="icon-double-angle-right"></i>
				{$crumbs}
			</small>
		</h1>
	</div>	
	<ul class="nav nav-tabs">
		
	  <li class="active"><a href="#tab-order" data-toggle="tab">订单详情</a></li>
	 
	  <li><a href="#tab-shipping" data-toggle="tab">收货地址</a></li>
	 
	  <li><a href="#tab-product" data-toggle="tab">商品清单</a></li>
	  
	  <li><a href="#tab-history" data-toggle="tab">订单历史</a></li>          
	  
	</ul>
	<div class="tab-content">
		<div class="tab-pane active" id="tab-order">
			<table class="table table-bordered">
				<tr>
				    <td>订单ID</td>
				    <td>{$data.order.order_id}</td>
				</tr>
				<tr>
					<td>订单编号</td>
					<td>{$data.order.order_num_alias}</td>
				</tr>
				<tr>
					<td>会员名称</td>
					<td>{$data.order.uname}</td>
				</tr>
				<tr>
				    <td>电子邮件</td>
				    <td>{$data.order.email}</td>
				</tr>
				  <tr>
				    <td>联系电话</td>
				    <td>{$data.order.telephone}</td>
				</tr> 
				<tr>
				    <td>合计金额</td>
				    <td>
				    	￥{$data.order.total}
				    </td>
				</tr>
				<tr>
				    <td>订单状态</td>
				    <td id="order-status">{$data.order.name}</td>
				</tr>     
				<tr>
					<td>IP地址</td>
					<td>{$data.order.ip_region}</td>
				</tr>  
				<tr>
					<td>用户系统</td>
					<td>{$data.order.user_agent}</td>
				</tr>
				<tr>
					<td>下单时间</td>
					<td>{$data.order.date_added|toDate='Y/m/d H:i:s'}</td>
				</tr>
				<tr>
					<td>修改时间</td>
					<td>{$data.order.date_modified|toDate='Y/m/d H:i:s'}</td>
				</tr>
				</table>
		</div>
		<div class="tab-pane" id="tab-shipping">
            <table class="table table-bordered">
          <tr>
            <td>收货人姓名</td>
            <td>{$data.order.shipping_name}</td>
          </tr>
                  
          <tr>
            <td>所在地</td>
            <td>
            	<?php echo get_area_name($data['order']['shipping_province_id']); ?>，
            	<?php echo get_area_name($data['order']['shipping_city_id']); ?>，
            	<?php echo get_area_name($data['order']['shipping_country_id']); ?>
            </td>
          </tr>
          
          <tr>
            <td>地址</td>
            <td>{$data.order.address}</td>
          </tr>
         
          <tr>
            <td>支付方式</td>
            <td><?php echo get_payment_name($data['order']['payment_code']); ?></td>
          </tr>
           <tr>
          	<td>货运方式</td>
          	<td><?php echo get_shipping_name($data['order']['shipping_method']); ?></td>
          </tr>
          <tr>
          	<td>联系电话</td>
          	<td>{$data.order.shipping_tel}</td>
          </tr>
          
        </table>
		
         
        
      </div>
      <div id="tab-product" class="tab-pane">
       <table class="table table-bordered">
          <thead>
            <tr>
              <td class="left">商品品名</td>
              <td class="left">型号</td>
              <td class="right">数量</td>
              <td class="right">价格</td>
              <td class="right">总计</td>
            </tr>
          </thead>
          <tbody>
          	<?php if(isset($data['order_product'])&&is_array($data['order_product'])){ ?>
	            <?php foreach ($data['order_product'] as $product) { ?>
	            <tr>
	              <td class="left"><a href="{:U('Goods/edit',array('id'=>$product['goods_id']))}"><?php echo $product['name']; ?></a>
	              
	              <td class="left"><?php echo $product['model']; ?></td>
	              <td class="right"><?php echo $product['quantity']; ?></td>
	              <td class="right">￥<?php echo $product['price']; ?></td>
	              <td class="right">￥<?php echo $product['total']; ?></td>
	            </tr>
	            <?php } ?>
            <?php } ?>
    
          </tbody>
          <?php if(isset($data['order_total'])&&is_array($data['order_total'])){ ?>
	          <?php foreach ($data['order_total'] as $totals) { ?>
	          <tbody id="totals">
	            <tr>
	              <td colspan="4" class="right"><?php echo $totals['title']; ?>:</td>
	              <td class="right"><?php echo $totals['text']; ?></td>
	            </tr>
	          </tbody>
	          <?php } ?>
          <?php } ?>
        </table>
  
      </div>
	
	
		 <div id="tab-history" class="tab-pane">
        <div id="history"></div>
        <table class="table table-bordered">
          <tr>
            <td>订单状态</td>
            <td>
              <input type="hidden" name="old_order_status_id" value="{$data.order.order_status_id}" id="old_order_status_id" />
              <select name="order_status_id">
                <?php foreach ($data['order_statuses'] as $order_statuses) { ?>
                	
                 <option value="<?php echo $order_statuses['order_status_id']; ?>" <?php if ($order_statuses['order_status_id'] == $data['order']['order_status_id']) { echo ' selected="selected"'; }?> ><?php echo $order_statuses['name']; ?></option>
               
                <?php } ?>
              </select>
            </td>
          </tr>
          <tr>
            <td>通知会员</td>
            <td><input type="checkbox" checked="checked" name="notify" value="1" /></td>
          </tr>
          <tr>
            <td>订单附言</td>
            <td><textarea name="comment" cols="40" rows="8" style="width: 99%"></textarea>
            </td>
           </tr>
           <tr>
           	<td colspan="2">
          <div class="text-right">
			<button id="button-history" class="btn btn-primary" data-loading-text="Loading...">
			<i class="fa fa-plus-circle"></i>
			添加订单记录
			</button>
		  </div>
		  </td>
          </tr>
        </table>
      </div>	
		
	</div>
</block>
<block name="javascript">
<script>	
$('#history').load('<?php echo U("Order/history",array("id"=>I("id"))); ?>');
$('#button-history').live('click', function() {

	$.ajax({
		url: '<?php echo U("Order/history",array("id"=>I("id"))); ?>',
		type: 'post',
		dataType: 'html',
		data: 'order_status_id=' + encodeURIComponent($('select[name=\'order_status_id\']').val()) + '&notify=' + encodeURIComponent($('input[name=\'notify\']').attr('checked') ? 1 : 0)  + '&comment=' + encodeURIComponent($('textarea[name=\'comment\']').val()),
		beforeSend: function() {
			$('.success, .warning').remove();
			$('#button-history').attr('disabled', true);
			$('#history').prepend('<div class="attention"><img src="__IMG__/loading.gif" alt="" />加载中...</div>');
		},
		complete: function() {
			$('#button-history').attr('disabled', false);
			$('.attention').remove();
		},
		success: function(html) {
			$('#history').html(html);
			
			$('textarea[name=\'comment\']').val('');
			
			$('#order-status').html($('select[name=\'order_status_id\'] option:selected').text());
		}
	});
});
</script>
</block>